import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'
import Actives from "../views/Actives";
import Mine from '@/views/Mine'

import login from '@/components/visit/login'
import register from '@/components/visit/register'

import token from '@/apis/refresh_token'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/Home.vue')
  },
  {
    path: '/mine',
    name: 'Mine',
    component: Mine
  },
  {
    path: '/add',
    name: 'Add',
    component: () => import('../views/AddNew.vue')
  },
  {
    path: '/actives',
    name: 'Actives',
    component: () => import('../views/Actives.vue')
  }
]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, go) => {
  // console.log(to, from)
  if (to.path == '/mine') {
    go ()
  } else {
    // 这里前端只需要管用户有没有登录，其他各个接口权限都有token认证
    if (localStorage.getItem('pta_username')) {
      go ()
    }
  }

 
})

export default router
